let list = []

$("#mm").hide();
$.ajax({
    url: "userseat/list",
    type: "get",
    dataType: "json",
    success: function (data) {
        list = data.records
        console.log(data);
        let h = "<p>"+data.total+"</p>";
        for (let i = 0; i < data.total; i++) {
            console.log(data.records[i])
            h += '<tr>\n' +
                '    <td>' + list[i].id + '</td>\n' +
                '    <td>' + list[i].uid + '</td>\n' +
                '    <td>' + list[i].seatid + '</td>\n' +
                '    <td><button type="button" class="layui-btn layui-btn-warm" onclick="upd(' + list[i].id + ')">修改</button><button type="button" class="layui-btn layui-btn-danger" onclick="del(' + list[i].id + ')">删除</button></td>\n' +
                '  </tr>';
        }

        $("#tbody").html(h);
    }
});
function login(){
    login_pwd=$("#user").val()
    if(login_pwd=="sry"){
        $("#login").toggle();
        $("#main").toggle();
    }else{
        window.location.reload();
    }
}

function del(id) {
    $.ajax({
        url: "userseat/delete/" + id,
        type: "get",
        dataType: "json",
        success: function (data) {
            window.location.reload();
        }
    })
}

function upd(id) {

    console.log(id);
    $("#mm").toggle();
    $("#add").toggle();
    $.ajax({
        url: "userseat/get/" + id,
        type: "get",
        dataType: "json",
        success: function (data) {
            $("#id").val(data.id);
            $("#uid").val(data.uid);
            $("#pwd").val(data.pwd);
            $("#seatid").val(data.seatid);
        }
    })
}


function add() {

    $("#mm").toggle();
    $("#add").toggle();
    $("#id").val(-1);
    $("#uid").val("");
    $("#pwd").val("");
    $("#seatid").val("");
}


function aou() {
    id = $("#id").val()
    uid = $("#uid").val() + ""
    pwd = $("#pwd").val() + ""
    seatid = $("#seatid").val() + ""

    console.log(seatid);
    const userseat={
        "id":id,
        "uid": uid,
        "pwd": pwd,
        "seatid": seatid
    }
    console.log(id + uid + pwd + seatid)
        $.ajax({
            url: "userseat/aou",
            type: "get",
            dataType: "json",
            data: userseat,
            success: function (data) {
                data ? alert("成功或未修改!") : alert("失败!");
                window.location.reload();
            }
        })
}